﻿// <copyright file="Program.cs" company="QUT">
//     Copyright (c) QUT. All rights reserved.
// </copyright>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using LRT.Engine;

namespace LRT.CommandLine
{
    /// <summary>
    /// The Localisation Resource Toolkit Console application.
    /// </summary>
    public class Program
    {
        /// <summary>
        /// Mains the specified args.
        /// </summary>
        /// <param name="args">The supplied args.</param>
        public static void Main(string[] args)
        {
            if (args.Length >= 2)
            {
                string source = args[0];
                string targetCulture = args[1];
                bool useTranslationMemory = false;
                bool useGoogleTranlate = false;
                for (int i = 2; i < args.Length; i++)
                {
                    string arg = args[i];
                    if (arg.ToLower() == "-tm")
                    {
                        useTranslationMemory = true;
                    }
                    else if (arg.ToLower() == "-gt")
                    {
                        useGoogleTranlate = true;
                    }
                }

                try
                {
                    ResourceGenerator engine = new ResourceGenerator(source, targetCulture, useTranslationMemory, useGoogleTranlate);
                    engine.Save();
                    Console.WriteLine("Resource file {0} created", engine.TargetFilePath);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: {0}\n", ex.Message);
                }

                return;
            }

            ShowUsage();
        }

        /// <summary>
        /// Shows the usage.
        /// </summary>
        public static void ShowUsage()
        {
            Console.WriteLine("Usage: LRTConsole.exe source targetCulture [-tm -gt]");
            Console.WriteLine("\t source         The source resource file (*.resx)");
            Console.WriteLine("\t targetCulture  The target language locale.");
            Console.WriteLine("\t -tm            Optional switch. Use translation memory.");
            Console.WriteLine("\t -gt            Optional switch. Use Google Translate.\n");
        }
    }
}
